<template>
  <div class="tkshryap">
    <div class="selected-module">
      <el-card>
        <i class="el-icon-search"></i>
        <div class="select-item">
          <span>流程名称：</span>
          <el-input v-model="processName" placeholder="请输入内容" clearable></el-input>
        </div>
        <div class="btn-group">
          <el-button type="primary">查询记录</el-button>
          <el-button type="danger">清除条件</el-button>
        </div>
      </el-card>
    </div>
    <div class="table-module">
      <el-card>
        <div class="btn-group">
          <el-button type="primary" @click="addRecord">添加记录</el-button>
          <el-button type="danger" @click="deleteRecord">删除记录</el-button>
        </div>
        <el-table
          :data="tableData"
          border
          style="width: 100%">
          <el-table-column
            label="显示顺序"
            type="index"
            width="50">
          </el-table-column>
          <el-table-column
            prop="date"
            label="名称"
            width="180">
          </el-table-column>
          <el-table-column
            prop="name"
            label="审核最小天数"
            width="180">
          </el-table-column>
          <el-table-column
            prop="name"
            label="人员安排"
            width="180">
          </el-table-column>
          <el-table-column
            prop="address"
            label="流程说明">
          </el-table-column>
          <el-table-column
            fixed="right"
            label="操作"
            width="120">
            <template slot-scope="scope">
              <el-button
                @click.native.prevent="handleClick(scope.$index, tableData)"
                type="text"
                size="small">
                配置操作人员
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
    </div>
    <div class="dialog-module">
      <!--以前的弹框可以用-->
      <el-dialog title="审核人员设置" :visible.sync="dialogEquipVisible" custom-class="equip-dialog">
        <div class="content">
          <el-transfer v-model="transferValue" :data="transferData" :titles="['部门内人员列表', '已选人员列表']"></el-transfer>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogEquipVisible = false">取 消</el-button>
          <el-button type="primary" @click="sendParams">确 定</el-button>
        </div>
      </el-dialog>
    </div>
    <div class="dialog-module">
      <el-dialog title="新增记录" :visible.sync="dialogAddVisible" custom-class="equip-dialog">
        <div class="content">
          <div class="content-item">
            <span>流程名称：</span>
            <el-input v-model="addDialogValue1"></el-input>
          </div>
          <div class="content-item">
            <span>显示顺序：</span>
            <el-input v-model="addDialogValue2"></el-input>
          </div>
          <div class="content-item">
            <span>说明：</span>
            <el-input v-model="addDialogValue3"></el-input>
          </div>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogAddVisible = false">取 消</el-button>
          <el-button type="primary" @click="saveParams">保存退出</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<style lang="scss" scoped>
  .tkshryap {
    .selected-module {
      .el-icon-search {
        font-size: 34px;
      }
      .select-item {
        display: inline-block;
        .el-input {
          display: inline-block;
          width: 200px;
        }
      }
      .btn-group {
        float: right;
      }
    }
    .table-module {
      .btn-group {
        margin-bottom: 10px;
      }
    }
    .dialog-module {

    }
  }
</style>

<script>
  import {getToken} from "../../utils/auth";
  export default {
    data() {
      return {
        processName: '',
        tableData: [
          {
          date: '2016-05-02',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          date: '2016-05-04',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1517 弄'
        }, {
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1519 弄'
        }, {
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1516 弄'
        }],
        dialogEquipVisible: false,
        dialogAddVisible: false,
        transferValue: [],
        transferData: [
          {
            key: '张哲',
            label: '张哲'
          },
          {
            key: '小眼',
            label: '小眼'
          },
          {
            key: '某某某',
            label: '某某某'
          }
        ],
        currentIndex: 1,
        showPage: 10,
        addDialogValue1: '',
        addDialogValue2: '',
        addDialogValue3: '',

      }
    },
    methods: {
      handleClick() {
        this.dialogEquipVisible = true
      },
      async loadTableData() {
        let params = {
          token: getToken(),
          index: this.currentIndex,
          pagemax: this.showPage,
          processName: this.processName
        }
        let res = await this.axios.get('v1/jstk/ryap/getdata', {params})
        // 接口有问题，没又解析很缺
        // console.log(res)
        // this.tableData = res.data.data
      },
      addRecord() {
        this.dialogAddVisible = true
      },
      deleteRecord() {},
      async saveParams() {
        this.dialogAddVisible = false
        let params = {
          token: getToken(),
          processName: this.addDialogValue1,
          displayOrder: this.addDialogValue2,
          explain: this.addDialogValue3,
          minDay: '',
        }
        let res = await this.axios.post('v1/jstk/ryap/add_action', params)
        console.log(res)
      },
      async sendParams() {
        this.dialogEquipVisible = false
        let params = {
          token: getToken(),
          id: '', //当前索引
          staffing: this.transferValue
        }
        let res = await this.axios.post('v1/jstk/ryap/allot_teacher', params)
        console.log(res)
      }
    },
    created() {
      this.loadTableData()
    }
  }
</script>
